package com.sk.sqd.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理的实现类，如果代理的方法被调用，代理会通知和转发给 InvocationHandler 的实现类，由它调用 invoke() 去处理
 */
public class ProxyHandler implements InvocationHandler {

    private Object proxied;

    public ProxyHandler(Object proxied) {
        this.proxied = proxied;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理类前置处理~~~");
        Object obj = method.invoke(proxied, args);
        System.out.println("代理类后置处理~~~");
        return obj;
    }
}
